# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

pkgname=hledger-web
pkgver=1.31
pkgrel=36
pkgdesc="Web-based user interface for the hledger accounting system"
url="http://hledger.org"
license=("GPL")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'hledger' 'haskell-hledger-lib' 'haskell-aeson' 'haskell-base64'
         'haskell-blaze-html' 'haskell-blaze-markup' 'haskell-case-insensitive'
         'haskell-clientsession' 'haskell-cmdargs' 'haskell-conduit' 'haskell-conduit-extra'
         'haskell-data-default' 'haskell-decimal' 'haskell-extra' 'haskell-hjsmin'
         'haskell-hspec' 'haskell-http-conduit' 'haskell-http-client' 'haskell-http-types'
         'haskell-megaparsec' 'haskell-network' 'haskell-shakespeare' 'haskell-unix-compat'
         'haskell-unordered-containers' 'haskell-utf8-string' 'haskell-wai' 'haskell-wai-cors'
         'haskell-wai-extra' 'haskell-wai-handler-launch' 'haskell-warp' 'haskell-yesod'
         'haskell-yesod-core' 'haskell-yesod-form' 'haskell-yesod-static' 'haskell-yesod-test')
makedepends=('ghc')
replaces=('hledger-api')
source=("https://hackage.haskell.org/packages/archive/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('c2ba97f63dd02456bf9e2f653b7384867d2155326b7512ea654a7c9ec1c77d11e5e52a07b31c0d1955e4c72ee531ca89a10c7127c943ceb10a1dbcf86405c4c5')

build() {
    cd $pkgname-$pkgver
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir="/usr/share/doc/$pkgname" --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -f-dev -f-library-only -fthreaded
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $pkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $pkgname-$pkgver
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE

    install -Dm644 hledger-web.1 -t "$pkgdir"/usr/share/man/man1/
}
